package com.logistics.material.controller;


import com.logistics.inventory.service.InventoryService;
import com.logistics.material.entity.model.MaterialPickSave;
import com.logistics.material.entity.model.WmsPickSave;
import com.logistics.material.service.MaterialPickService;
import com.logistics.pick.entity.model.PickSave;
import com.logistics.pick.entity.model.PickDetailSave;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * agv主数据 前端控制器
 * </p>
 *
 * @author yunjian.ban
 * @since 2024-05-21
 */
@RestController
@RequestMapping("lgs/material/pick")
public class MaterialPickController {

    @Autowired
    private MaterialPickService materialPickService;

    /**
     * 物料拣配-查询物料单据信息
     *
     * @param code
     * @return
     */
    @GetMapping("/search/{code}")
    @LoggerListener(businessName = "物料拣配-查询物料单据信息", methodName = LoggerMethod.SEARCH)
    public ResponseEntity pick(@PathVariable("code") String code) throws MessageException {
        return ResponseUtil.success(materialPickService.material(code, null));
    }

    /**
     * 物料拣配-查询物料单据信息(涂装车间)
     *
     * @param code
     * @return
     */
    @GetMapping("/search/{code}/{billNo}")
    @LoggerListener(businessName = "物料拣配-查询物料单据信息(涂装车间)", methodName = LoggerMethod.SEARCH)
    public ResponseEntity paintPick(@PathVariable("code") String code, @PathVariable("billNo") String billNo) throws MessageException {
        return ResponseUtil.success(materialPickService.material(code, billNo));
    }

    /**
     * 物料拣配-保存物料信息
     *
     * @param save
     * @return
     */
    @PutMapping("/save")
    @LoggerListener(businessName = "物料拣配-保存物料信息", methodName = LoggerMethod.SAVE)
    public ResponseEntity savePick(@RequestBody MaterialPickSave save) throws MessageException {
        materialPickService.saveMaterial(save);
        return ResponseUtil.success();
    }

    /**
     * 查找物料列表
     *
     * @param pickId
     * @return
     */
    @GetMapping("/list/{pickId}/{container}")
    @LoggerListener(businessName = "物料拣配-查询物料列表", methodName = LoggerMethod.SEARCH)
    public ResponseEntity listByPickId(@PathVariable("pickId") String pickId,
                                       @PathVariable("container") String container) {
        return ResponseUtil.success(materialPickService.listByPickId(pickId, container));
    }

    /**
     * 创建托盘
     *
     * @param params 查询参数
     * @return response实体
     */
    @PutMapping("/createContainer")
    @LoggerListener(businessName = "创建托盘和拣配单关系", methodName = LoggerMethod.SAVE)
    public ResponseEntity createContainer(@RequestBody PickSave params) throws MessageException {
        return ResponseUtil.success(materialPickService.createContainer(params));
    }

    /**
     * 移除托盘
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/removeContainer/{ids}")
    @LoggerListener(businessName = "删除托盘", methodName = LoggerMethod.DELETE)
    public ResponseEntity removeContainer(@PathVariable("ids") String ids) throws MessageException {
        materialPickService.removeContainer(ids);
        return ResponseUtil.success();
    }

    /**
     * 更新数量
     *
     * @param params
     * @return
     */
    @PutMapping("/updateItemQty")
    @LoggerListener(businessName = "更新数量", methodName = LoggerMethod.SAVE)
    public ResponseEntity updateItemQty(@RequestBody PickDetailSave params) throws MessageException {
        materialPickService.updateItemQty(params);
        return ResponseUtil.success();
    }

    /**
     * 移除物料
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/removeMaterial/{ids}")
    @LoggerListener(businessName = "移除物料", methodName = LoggerMethod.SAVE)
    public ResponseEntity removeMaterial(@PathVariable("ids") String ids) throws MessageException {
        materialPickService.removeMaterial(ids);
        return ResponseUtil.success();
    }

    /**
     * wms拣配
     * @param params
     * @return
     * @throws MessageException
     */
    @PutMapping("/wmsPick")
    public ResponseEntity wmsPick(@RequestBody WmsPickSave params) throws MessageException {
        materialPickService.wmsPick(params);
        return ResponseUtil.success();
    }

}

